<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP '5.jsp' starting page</title>
    <style type="text/css">
    	body {
			margin: 0;
			padding: 0;
			text-align: center;
			
		}
		#container{
			margin: 0, auto;
			
		}
		#main{
			background-color: #1E90FF;
			width: 800;
			height: 450;
		}
		#content{
			position: relative;
			background: white;
			height: 420px;
			overflow： auto;
			margin: 10px, 15px;
		}
		.bindClick{
			position: relative;
			padding: 10px 10px 10px 0px;
			margin: 0;
			border-bottom: 1px solid #aaa;
			overflow: hidden;
			cursor: pointer;
			zoom: 1;
		}
		.left_Read{
			text-align: left;
			
			width: 520px;
			height: 44px;
			margin: 0 80px 0 1px;
			white-space: normal;
			line-height: 22px;
			word-break: break-all;
			word-wrap: break-word;
			word-spacing: 3px;
			overflow: hidden;
		}
		.left_Unread{
			text-align: left;
			
			width: 520px;
			height: 44px;
			margin: 0 80px 0 1px;
			white-space: normal;
			line-height: 22px;
			word-break: break-all;
			word-wrap: break-word;
			word-spacing: 3px;
			overflow: hidden;
		}
		.right{
			
			float: right;
			display: block;
			margin-bottom: 6px;
			text-align: right;
			font-size: 11px;
			white-space: nowrap;
			color: #A0A0A0;
			width: 10%;
		}
		#footer{
			margin-top: 5px;
			/*
			position: absolute;
			bottom: 0px;
			margin: 0px;
			padding: 0px;
			*/
		}
		.aligncenter{
			text-align: center;
			line-height: 310px;
			font-size: 24px;
			font-weight: bold;
			font-family: "lucida Grande",Verdana;
		}
		
	</style>
    
    
    <script type="text/javascript" src="<%=path %>/js/jquery-1.6.2.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			
			querySession(1);
			
		});
		
		/*
		function makeSessionNode(id, topic, isReadS, joinTime){
			if(isReadS == "1"){
				return $('<div id="' + id + '" class="bindClick"><div class="left_Read">' + topic + '</div><div class="right">' + joinTime + '</div></div>');
			}else{
				return $('<div id="' + id + '" class="bindClick"><div class="left_Unread">' + topic + '</div><div class="right">' + joinTime + '</div></div>');
			}
		}
		*/
		
		function querySession(pageIndex){
			$.ajax({
				type: "GET",
				url: "<%=path %>/ajax",
				data: {method: 'getPublicSession', pageSize: '5', pageIndex: pageIndex, random: Math.random()},
				dataType: "json",
				success : function(data, textStatus){
					$('#detail').empty();
					var total = data.total;
					if(total == 0){
						$('#content').empty();
						$('#content').append('<div class="aligncenter">没有意见信息</div>');
					}
					var sesssion_array = data.session_lst;
					if(sesssion_array != null){
						$.each(sesssion_array, function(i,node){
							//$('#d1').append(makeSessionNode(node.id, node.topic, node.isRead, node.joinTime));
							//alert(node.topic);
							$('#detail').append(makeSessionNode(node.id, node.topic, node.isReadS, node.joinTime));
						});
					}
					$('.bindClick').bind('mouseover',function(){
						$(this).css('background-color','#FFE4C4');
					}).bind('mouseout',function(){
						$(this).css('background-color','white');
					}).bind('dblclick',function(){
						var id = $(this).attr('id');
						var url = '<%=path %>/jsp/publicChatDetail.jsp?id=' + id;
						window.open(url,"_self");
					});
					$('#current').text(pageIndex);
					if(total%5 != 0){
						total = parseInt(total/5) + 1;
					}else{
						total = parseInt(total/5);
					}
					
					$('#total').text(total);
					
					
					var total2 = parseInt($('#total').text());
					var flag = 1;
					if(total2 == pageIndex && pageIndex == 1){
						$('#next').hide();
						$('#prev').hide();
						flag = 0;
					}else if(total2 == pageIndex){
						$('#next').hide();
						$('#prev').show();
						flag = 0;
					}else if(pageIndex == 1){
						$('#prev').hide();
						$('#next').show();
						flag = 0;
					}
					if(flag == 1){
						$('#next').show();
						$('#prev').show();
					}
					
				},
				error : function(){
					alert("请求失败");
				}
			});
			
			
		}
		
		function makeSessionNode(id, topic, isReadS, joinTime){
			return $('<div id="' + id + '" class="bindClick"><div class="right">' + joinTime + '</div><span class="left_Unread">' + topic + '</span></div>');
		}
		
		
	</script>
	
	
  </head>
  
  <body>
    <div id="container">
    	<div id="main">
    		<div id="content">
    			<div id="detail">
    			</div>
    			<div id="footer">
    				<center>
    					<span id="prev" style=""><a href="#" id="prevA" onclick="querySession(parseInt($('#current').text())-1)">上一页</a></span>
    					<span id="current" style="margin-left: 8px; margin-right: 1px">1</span> / <span id="total" style="margin-left: 1px;">1</span>
    					<span id="next" style="margin-left: 8px;"><a id="nextA" href="#" onclick="querySession(parseInt($('#current').text())+1)">下一页</a></span>
    				</center>
    			</div>
    		</div>
    	</div>
    </div>
  </body>
</html>
